window.onload=function(){
    //设置默认焦点事件
    document.getElementById('lname-focus5').focus();
}
function setStyle(x){
    document.getElementById(x).style.background="#eeeeee";
    document.getElementById(x).style.borderLeft="5px solid #666";
}
function loss(y){
    document.getElementById(y).style.background="#fafafa";
    document.getElementById(y).style.border="none";
}



var itemHeight = 40;

function openMenu(obj) {
    menu = document.getElementById('menu1');
    indicator = document.getElementById('indicator1');
    height = menu.style.height;

    if (height == "0px" || height == "") {
        childAmount = menu.getElementsByTagName('div').length;
        height = childAmount * itemHeight;
        menu.style.height = height + "px";
        indicator.style.transform = "rotate(-90deg)";
    } else {
        menu.style.height = "0px";
        indicator.style.transform = "rotate(0deg)";
    }
}
function del(){
    if(confirm("确定删除吗?")){
        var space_id=document.getElementById('space_id').value();
        window.document.location.href="${pageContext.request.contextPath}/deleteSpaceSubmit?id="+space_id;
    }
}
function updateSubmit(id){
    if(confirm("确定修改吗?")){
        document.getElementById(id).submit();
    }

}
var MitemHeight =120;
var MdividerHeight = 1;

function ManageopenMenu(obj) {
    menuTitleId = obj.id;
    menuId = "manage-menu" + menuTitleId.substring(17);
    indicatorId = "manage-indicator" + menuTitleId.substring(17);

    menu = document.getElementById(menuId);
    indicator = document.getElementById(indicatorId);
    height = menu.style.height;

    if (height == "0px" || height == "") {
        childAmount = menu.getElementsByTagName('div').length;
        dividerAmount = menu.getElementsByTagName('li').length;
        height = childAmount * MitemHeight + dividerAmount * MdividerHeight;
        menu.style.height = height + "px";
        indicator.style.transform = "rotate(90deg)";
    } else {
        menu.style.height = "0px";
        indicator.style.transform = "rotate(0deg)";
    }
}

function updateStatus(status,member_id){
    var status;
    if(status==1){
        status=2;
    }else{
        status=1;
    }

    $.ajax({
        url: "/member/updateStatus",
        type : "post",
        contentType : "application/x-www-form-urlencoded",
        data:"status="+status+"&member_id="+member_id,
        complete: function (XMLHttpRequest) {
            // 通过xhr取得响应头
            const REDIRECT = XMLHttpRequest.getResponseHeader("REDIRECT");
            //如果响应头中包含 REDIRECT 则说明是我们需要进行重定向的
            if (REDIRECT == "REDIRECT") {
                window.location.href = XMLHttpRequest.getResponseHeader("CONTEXTPATH");
            }
        },
        traditional: true,//使用传统方式浅层序列化，可以传递数组
        success:function(data){
        }
    });

}

/********************分页实现***************************/
$(function(){
    //可改变当前页的a样式
    $("#page_btn4").css("background-color","#4f90fb");
    $("#page_btn4").css("border","1px solid #ddd");
    $("#page_btn4").css("color","#fff");

    //得到当前页数：
    var currentPage=document.getElementById("page_btn4").innerText;
    //获得总页数:
    var pageNum=document.getElementById("page_btn7").innerText;
    //先处理"上一页"和"下一页"的情况
    if(currentPage==1) //如果当前页为首页
    {
        $("#prePage").hide();
        $("#page_btn2").hide();
        $("#page_btn3").hide();
    }
    if(currentPage==2)//当前页是2则也需要hide掉第二个按钮（此时为-1）
    {
        $("#page_btn2").hide();
    }
    if(currentPage==pageNum) //如果当前页为末页
    {
        $("#sufPage").hide();
        $("#page_btn5").hide();
        $("#page_btn6").hide();
    }
    if(currentPage==pageNum-1)
    {
        $("#page_btn6").hide();
    }

    //处理当前页小于等于3的特殊情况
    if(currentPage<=3){
        $("#prePoint").hide();
        $("#page_btn1").hide();
    }//当前页是4还需要hide掉第一个省略号按钮
    else if(currentPage==4){
        $("#prePoint").hide();
    }

    //最末端的特殊情况处理和最前端是一样的
    if(currentPage>=pageNum-2){
        $("#sufPoint").hide();
        $("#page_btn7").hide();
    }
    else if(currentPage==pageNum-3){
        $("#sufPoint").hide();
    }

});
